package tree.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @author: zxw
 * @version: v1.0
 * @description:
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MyTreeNode<T> extends BaseUidDo {


    private static final Logger LOGGER = LoggerFactory.getLogger(MyTreeNode.class);
    private List<T> children;
    private String name;
    private String label;
    private String description;
    /**
     * 结构树中上一级节点的UID
     */
    private String parentUid;
    private String uidPath;
    private Integer level;
    private LocalDateTime effectiveStartTimestamp;
    private LocalDateTime effectiveEndTimestamp;
    private Integer version;

    private Integer state;
    private Comparable<?> weight = 0;

    public MyTreeNode(String id, String parentId, String name) {
        this.setUid(id);
        this.parentUid = parentId;
        this.name = name;
    }

    public static void main(String[] args) {
        long t = System.currentTimeMillis();
        Date d1 = new Date(t);
        Date d2 = new Date(t);
        System.out.println(Objects.equals(d1, d2));
    }

    public Comparable<?> getWeight() {
        return weight;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MyTreeNode<?> treeNode = (MyTreeNode<?>) o;
        return Objects.equals(getUid(), treeNode.getUid()) &&
                Objects.equals(getName(), treeNode.getName()) &&
                Objects.equals(getLabel(), treeNode.getLabel()) &&
                Objects.equals(getUidPath(), treeNode.getUidPath()) &&
                Objects.equals(getEffectiveStartTimestamp(), treeNode.getEffectiveStartTimestamp()) &&
                Objects.equals(getEffectiveEndTimestamp(), treeNode.getEffectiveEndTimestamp()) &&
                Objects.equals(getDeleted(), treeNode.getDeleted()) &&
                Objects.equals(getState(), treeNode.getState()) &&
                Objects.equals(getDescription(), treeNode.getDescription())
                ;
    }

    @Override
    public int hashCode() {
        return Objects.hash(getUid(), getName(), getLabel(), getUidPath(), getEffectiveStartTimestamp(), getEffectiveEndTimestamp(), getDeleted(), getDescription());
    }
}
